Ext.define('Holo.controller.WindowsNewApp', {
    extend: 'Ext.app.Controller',
	
    views: [
        'app.WindowsNewApp'
    ],
    
    stores: [
        'Apps',
    ],
    
    
    refs: [
            {
                selector: '#WindowsNewAppForm',
                ref: 'formNewApp'
            },{
                selector: 'windowsnewapp',
                ref: 'WindowsNewApp'
            }
    ],



    
    init: function() {
    	 this.control({
                'windowsnewapp' :{
		    //afterrender : this.affectKeyMap
                    afterlayout : function (form){
                        GlobalData.currentController = this;
                    } 
                },
                
	        'windowsnewapp button[action=createapp]': {
		    click : this.createNewApp
                }  
        
        });
    },
    
    
    createNewApp : function(){
        var newAppData = this.getFormNewApp().getValues();
	if(newAppData.name!=''){
	    try{
		var newApp = Ext.create('Holo.model.App', {
					    name:newAppData.name + '-' + newAppData.codelang,
					    type: 'E',
                                            status : 'D',
					    language: newAppData.codelang,
					    user_id : GlobalData.currentUserId
					});
	    
		this.getAppsStore().add(newApp);
	    }catch(err){
		console.log('erreur : controller/WindowsNewApp.createNewApp() =>'+ err.message);
	    }
	}
    },
    
    screenUpdate : function(){
            
        var controllerMenu = this.getController('MainMenu');
        controllerMenu.setItemsToSelectAppMenu();
        controllerMenu.showAppManager();
        
        this.getWindowsNewApp().close();   
        
    }
  
 });